/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.trabajo.dao;

import com.trabajo.entidad.Cliente;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author jerick
 */
public class ClienteDAO {
    private EntityManagerFactory emf;
    private EntityManager em;

    public ClienteDAO() {
        emf=Persistence.createEntityManagerFactory("trabajoPU");
        em=emf.createEntityManager();
    }
     public void closeEntityManager(){
        em.close();
    }
   /* public List<Cliente> buscarEmpleado(String usuario,String codigo)
    {
        Query q=(Query) em.createQuery("SELECT e FROM Empleado e where e.usuarioEmp = '" + usuario + "' and e.codEmp = '" + codigo +"'");
        return q.getResultList();
    }*/
     //public List<Cliente>  buscar_cliente(String Ruc)
     public Cliente  buscar_cliente(String Ruc)
     {
         //Query q=(Query) em.createQuery("SELECT c FROM Cliente c where c.ruc = '" + Ruc + "'" );
         Cliente c=em.find(Cliente.class, Ruc);
         //return q.getResultList();
         return c;
     }
    public boolean insertarCliente(Cliente c)
    {
        boolean b=false;
        try
        {
            em.getTransaction().begin();
            em.persist(c);
            em.getTransaction().commit();
            b=true;
        }catch(Exception e){
            em.getTransaction().rollback();
                    
        }
        return b;
    }
}
